<?php

namespace app\beautiful\helper\payment;

use app\common\helper\payment\PaymentBaseHelper;

class  PaymentMicropayHelper extends PaymentBaseHelper
{
    protected $orderKey = 'beautiful_cashier';

    //发送扫码支付的
    public function sendPayment($order)
    {
        if (empty($order['product_name']) || empty($order['order_id']) || empty($order['need_pay']) || empty($order['auth_code'])) {
            return false;
        }
        $newOrder = [
            'body' => $order['product_name'],
            'out_trade_no' => $this->orderKey . $order['order_id'], //增加4位随机数防止订单号的重复
            'total_fee' => $this->shopId == 20210009 ? '1' : (int)($order['need_pay'] * 100),//调试设置为1
            'auth_code' => $order['auth_code'],
        ];
        $return = $this->app->base->pay($newOrder);
        wyuLog('cashier.txt', "请求结果：" . var_export($return, true));
        return $return;
    }

    public function queryOrder($orderId)
    {
        $out_trade_no = $this->orderKey . $orderId;
        $return = $this->app->order->queryByOutTradeNumber($out_trade_no);
        wyuLog('cashier.txt', "查询结果：" . var_export($return, true));
        return $return;
    }

    public function cancelPay($orderId)
    {
        $out_trade_no = $this->orderKey . $orderId;
        $return = $this->app->reverse->byOutTradeNumber($out_trade_no);
        wyuLog('cashier.txt', "撤銷结果:" . var_export($return, true) . "\r");
        return $return;
    }

}